package com.dongdongshop.domain;

import com.dongdongshop.constant.ResultConstant;
import com.dongdongshop.em.ResultEnum;

public class AjaxResult<T> {
    private Integer code;
    private String message;
    private T data;


    //返回正确的
    public static AjaxResult OK(){
        AjaxResult result = new AjaxResult();
        result.setCode(ResultEnum.SUCCESS.getStatus());
        result.setMessage(ResultEnum.SUCCESS.getStatusInfo());
        return result;
    }

    //返回错误的
    public static AjaxResult ERROR(){
        AjaxResult result = new AjaxResult();
        result.setCode(ResultEnum.ERROR.getStatus());
        result.setMessage(ResultEnum.ERROR.getStatusInfo());
        return result;
    }

    //其他未知错误的返回状态
    public static AjaxResult R(ResultEnum resultEnum){
        AjaxResult result = new AjaxResult();
        result.setCode(resultEnum.getStatus());
        result.setMessage(resultEnum.getStatusInfo());
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public AjaxResult setData(T data) {
        this.data = data;
        return this;
    }
}
